// Copyright 2022 jeff.li. and/or its affiliates.

#pragma once

#include <stdint.h>

namespace tbir::runtime {

    inline constexpr int64_t slice_index_correction(int64_t slice, int64_t len) noexcept {
        // change slice to [0, len)
        return slice < 0 ? (slice < -len ? 0 : slice + len) : (slice > len ? len : slice);
    }

    inline constexpr int64_t index_correction(int64_t index, int64_t len) noexcept {
        return index < 0 ? index + len : index;
    }

}  // namespace tbir::runtime
